import { debounce } from '@/common/utils'

export default {
    watch: {
        data: {
            handler() {
                this.chart.resize()
            },
            deep: true
        }
    },
    mounted() {
        this.$nextTick(function () {
            this.__resizeHandler = debounce(() => {
                if (this.chart) {
                    this.chart.resize()
                }
            }, 100)
            // window.addEventListener('resize', this.__resizeHandler)
    
            // const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
            // sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
        });
    },
    beforeDestroy() {
        if (!this.chart) {
            return
         }
        this.chart.dispose()
        this.chart = null
        window.removeEventListener('resize', this.__resizeHandler)
        // const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
        // sidebarElm.removeEventListener('transitionend', this.sidebarResizeHandler)
    },
    methods: {
        // sidebarResizeHandler(e) {
        //     if (e.propertyName === 'width') {
        //         this.__resizeHandler()
        //     }
        // }
    }
}
